﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediPlatform.ErrorCode
{
    public class ApiResult<T>
    {
        public BaseEnums Code { get; set; }
        public string Msg { get; set; }
        public T Data { get; set; }

        /// <summary>
        /// 创建成功结果
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="message">消息</param>
        /// <returns>API结果</returns>
        public static ApiResult<T> Success(T data, string message = "操作成功")
        {
            return new ApiResult<T>
            {
                Code = BaseEnums.Success,
                Msg = message,
                Data = data
            };
        }

        /// <summary>
        /// 创建错误结果
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="code">错误代码</param>
        /// <returns>API结果</returns>
        public static ApiResult<T> Error(string message, BaseEnums code = BaseEnums.Fail)
        {
            return new ApiResult<T>
            {
                Code = code,
                Msg = message,
                Data = default(T)
            };
        }
    }
}
